<%@page import="service.ProgressTestDao"%>
<%@page import="models.Answer"%>
<%@page import="models.Question"%>
<%@page import="java.util.Set"%>
<%@page import="models.Test"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%@page import="java.util.List"%>
<%@page import="models.Course"%>
<%@page import="models.User"%>
<%@page import="service.UserDao"%>
<%@page import="org.hibernate.Session"%>
<%@page import="service.HibernateUtil"%>
<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
        <link href="style/tutor.css" type="text/css" rel="Stylesheet">
        <!-- include jQuery Library From Google Code -->
        <script src="//ajax.googleapis.com/ajax/libs/jquery/1.8.0/jquery.min.js" type="text/javascript"></script>

        <script type="text/javascript">
            $(document).ready(function(){
                $("#floatingMenu").click(function () {
                    $('#floatingMenuContent').slideToggle();
                });
             
                $("#cancelTest").click(function(){
                    $('#newtest').hide();                  
                });
                
                $("#createTest").click(function(){
                    $('#newtest').show();                  
                });
                
                
            });
        </script>
            <jsp:useBean id="inhoud" scope="application" class="models.Bean" />   
            <jsp:setProperty name="inhoud" property="language" value="<%= models.Bean.getLanguage() %>" />
        <title>
            Three 2 Learn
        </title>
    </head>
    <body>       
        <div id="wrapper">
            <jsp:include page="sidebar.jsp"/>
            <div id="right">
                <jsp:include page="courseDescriptionList.jsp"/>         

                <h1><jsp:setProperty name="inhoud" property="key" value="ProgressTestManagement" />
                     <jsp:getProperty name="inhoud" property="key" /></h1>
                <h2><jsp:setProperty name="inhoud" property="key" value="SelectACourse" />
                     <jsp:getProperty name="inhoud" property="key" /></h2>
                <!-- display assigned courses of teacher!-->
                <table width="100%">
                    <tr>
                        <c:choose>             
                            <c:when test="${not empty courses}">
                                <c:forEach var="course" items="${courses}" varStatus="loop">
                                    <c:if test="${not loop.first and loop.index % 3 == 0}">
                                    </tr></tr>
                                </c:if>
                                <td width="20%">
                                    <a href="/progress?sc=${course.getCourseID()}">${course.getName()}</a>
                                </td>
                            </c:forEach>
                        </c:when>
                        <c:otherwise>
                            <jsp:setProperty name="inhoud" property="key" value="NoCoursesAssigned" />
                            <jsp:getProperty name="inhoud" property="key" />
                        </c:otherwise>
                    </c:choose>
                    </tr>
                </table>

                <!-- nieuwe test maken!-->
                <div id="newtest">
                    <table width="100%">
                        <th colspan="2"><jsp:setProperty name="inhoud" property="key" value="NewProgressTestFor" />
                                        <jsp:getProperty name="inhoud" property="key" /> <b>${selectedCourse.name}</b>
                            <a class="button float" href="#" id="cancelTest"><jsp:setProperty name="inhoud" property="key" value="CancelTest" />
                                                                             <jsp:getProperty name="inhoud" property="key" /></a>
                        </th>
                        <form action="/progress?type=create" method="post">
                            <tr class="darker">
                                <td colspan="3">
                                    <p><jsp:setProperty name="inhoud" property="key" value="GiveYourTestAName" />
                                       <jsp:getProperty name="inhoud" property="key" /></p>
                                </td>
                            </tr>
                            <tr>
                                <td><jsp:setProperty name="inhoud" property="key" value="TestName" />
                                    <jsp:getProperty name="inhoud" property="key" />:</td>
                                <td><input required="required"style="width: 100%" type="text" name="testname" id="testname" /></td>
                            <input type="hidden" name="course" value="${selectedCourse.courseID}"/>
                            </tr>
                            <tr>
                                <td colspan="2">
                                    <input type="submit" value="Add Test"/>
                                </td>
                            </tr>
                        </form>
                </div>
                </table>
            </div>

            <c:if test="${not empty selectedTest}">
                <h2><jsp:setProperty name="inhoud" property="key" value="Test" />
                    <jsp:getProperty name="inhoud" property="key" />: ${selectedTest.name}</h2>
                <table width="100%">
                    <th colspan="3"><jsp:setProperty name="inhoud" property="key" value="TestDetails" />
                                    <jsp:getProperty name="inhoud" property="key" />
                    </th>
                    <form action="/progress?type=add" method="post">
                        <input type="hidden" value="${selectedTest.testID}" name="testIDD" id="testIDD">
                        <tr class="darker" ><td colspan="3"><b><jsp:setProperty name="inhoud" property="key" value="MakeANewQuestion" />
                                                               <jsp:getProperty name="inhoud" property="key" /></b></td></tr>
                        <tr>
                            <td style="width:100px"><b><jsp:setProperty name="inhoud" property="key" value="Question" />
                                                      <jsp:getProperty name="inhoud" property="key" />:</b></td>
                            <td><input style="width:100%;"required="required" type="text" name="question"/></td>
                            <td style="width:100px;" rowspan="4"><a class="button" href="#" id="addQuestion"><input type="submit" value="Add Question"/></a></td></tr>
                        <tr>
                            <td><b><jsp:setProperty name="inhoud" property="key" value="Answer" />
                                   <jsp:getProperty name="inhoud" property="key" /> 1:</b></td>
                            <td>
                                <input required="required" style="width:100%;" type="text" name="answer_1">
                                <b><jsp:setProperty name="inhoud" property="key" value="AnswerIs" />
                                   <jsp:getProperty name="inhoud" property="key" />:</b>
                                <input type="radio" name="correct_1" value="true" checked> <jsp:setProperty name="inhoud" property="key" value="Correct" />
                                                                                           <jsp:getProperty name="inhoud" property="key" />
                                <input type="radio" name="correct_1" value="false"> <jsp:setProperty name="inhoud" property="key" value="Incorrect" />
                                                                                    <jsp:getProperty name="inhoud" property="key" />
                            </td>
                        </tr>
                        <tr>
                            <td><b><jsp:setProperty name="inhoud" property="key" value="Answer" />
                                   <jsp:getProperty name="inhoud" property="key" /> 2:</b></td>
                            <td>
                                <input required="required" style="width:100%;" type="text" name="answer_2">
                                <b><jsp:setProperty name="inhoud" property="key" value="AnswerIs" />
                                   <jsp:getProperty name="inhoud" property="key" />:</b>
                                <input type="radio" name="correct_2" value="true"> <jsp:setProperty name="inhoud" property="key" value="Correct" />
                                                                                   <jsp:getProperty name="inhoud" property="key" />
                                <input type="radio" name="correct_2" value="false" checked> <jsp:setProperty name="inhoud" property="key" value="Incorrect" />
                                                                                            <jsp:getProperty name="inhoud" property="key" />
                            </td>
                        </tr>
                        <tr>
                            <td><b><jsp:setProperty name="inhoud" property="key" value="Answer" />
                                   <jsp:getProperty name="inhoud" property="key" /> 3:</b></td>
                            <td>
                                <input required="required"style="width:100%;" type="text" name="answer_3">
                                <b><jsp:setProperty name="inhoud" property="key" value="AnswerIs" />
                                   <jsp:getProperty name="inhoud" property="key" />:</b>
                                <input type="radio" name="correct_3" value="true"> <jsp:setProperty name="inhoud" property="key" value="Correct" />
                                                                                   <jsp:getProperty name="inhoud" property="key" />
                                <input type="radio" name="correct_3" value="false" checked> <jsp:setProperty name="inhoud" property="key" value="Incorrect" />
                                                                                            <jsp:getProperty name="inhoud" property="key" />
                            </td>
                        </tr>
                    </form>
                    <c:if test="${not empty testQuestions}">
                        <c:if test="${not empty questionDetails}">
                            <th colspan="3"><jsp:setProperty name="inhoud" property="key" value="QuestionDetails" />
                                            <jsp:getProperty name="inhoud" property="key" /></th>
                            <c:forEach var="tempAnswer" items="${questionDetails}">
                                <tr><td><b><jsp:setProperty name="inhoud" property="key" value="Answer" />
                                           <jsp:getProperty name="inhoud" property="key" />:</b></td><td>${tempAnswer.answer}</td><td>${tempAnswer.correct}</td></tr>
                                
                            </c:forEach>
                        </c:if>
                        <tr class="darker"><td colspan="3"><b><jsp:setProperty name="inhoud" property="key" value="AllExistingQuestions" />
                                                              <jsp:getProperty name="inhoud" property="key" /></b></td></tr>
                        <c:forEach var="tempQuestion" items="${testQuestions}">
                            <tr>
                                <td><b><jsp:setProperty name="inhoud" property="key" value="Question" />
                                       <jsp:getProperty name="inhoud" property="key" />:</b></td>
                                <td>${tempQuestion.question} <a class="button float" href="/progress?type=answers&sq=${tempQuestion.questionID}"> <jsp:setProperty name="inhoud" property="key" value="Antwoorden" />
                                                                                                                                                  <jsp:getProperty name="inhoud" property="key" /></a></td>
                                <td><a href="/progress?type=delete&id=${selectedTest.testID}&sq=${tempQuestion.questionID}" class="button float"><jsp:setProperty name="inhoud" property="key" value="Verwijderen" />
                                                                                                                                                 <jsp:getProperty name="inhoud" property="key" /></a></td></tr>
                        </c:forEach>
                    </c:if>

                </table>
            </c:if>

            <c:if test="${not empty selectedCourse}">
                <div id="overview">
                    <h2><jsp:setProperty name="inhoud" property="key" value="ProgressTestsOf" />
                        <jsp:getProperty name="inhoud" property="key" /> ${selectedCourse.name}</h2>
                    <table width="100%">
                        <th><jsp:setProperty name="inhoud" property="key" value="AllTests" />
                            <jsp:getProperty name="inhoud" property="key" />
                            <a class="button float" href="#" id="createTest"><jsp:setProperty name="inhoud" property="key" value="CreateNewTest" />
                                                                             <jsp:getProperty name="inhoud" property="key" /></a>
                        </th>
                        <tr class="darker">
                            <td>
                                <p><jsp:setProperty name="inhoud" property="key" value="SelectTheTestYouWantToViewOrEdit" />
                                   <jsp:getProperty name="inhoud" property="key" /></p>                        
                            </td>
                        </tr>
                        <c:if test="${not empty courseTests}">                        
                            <c:forEach var="tempTest" items="${courseTests}" varStatus="loop">
                                <tr><td><a href="/progress?st=${tempTest.testID}">${tempTest.name}</a>
                                    <a href="/progress?st=${tempTest.testID}&type=delete" class="button float">Delete Teest</a>
                                    </td></tr>    
                            </c:forEach>
                        </c:if>
                        <c:if test="${empty courseTests}">
                            <tr><td><jsp:setProperty name="inhoud" property="key" value="NoTests" />
                                    <jsp:getProperty name="inhoud" property="key" />..</td></tr>
                        </c:if>
                    </table>
                </div>
            </c:if>
        </div>
    </div>
    </body>
</html>